 /**
 * Created by Administrator on 2016/12/14.
 */
!function () {
$(function() {
  function getCookie(name) {
    //取cookies函数
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null)
    return unescape(arr[2]);
    return null;
  }
  function delCookie(name){
    //删除cookie并重新演示
    // 该函数检查下cookie是否设置，如果设置了则将过期时间调到过去的时间;
    //剩下就交给操作系统适当时间清理cookie啦
    if (getCookie(name))
    {
    document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
    }
  $('#username').html(store.get('username'));
  $('#loginOut').on('click', function() {
    $.ajax({
      url: '/cloud/user/logOut',
      type: 'post',
      data: {},
      error: function() { layer.msg('服务器错误！操作失败')}
    })
    .done(function(result) {
      if (result.code === '0') {
        layer.msg('登录超时,即将跳转登录页')
        location.href="/login";
        delCookie('cloud');
        document.cookie = 'could=';
      } else if (result.code === '-1'){
        layer.msg('登录超时,即将跳转登录页')
        location.href = '/login';
      } else {
        layer.msg(result.msg, function(){
          //关闭后的操作
        });
      }
    })
  })
  
 
})
}();
